package net.lab1024.sa.admin.module.business.wms.stock.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.wms.stock.dao.StockDao;
import net.lab1024.sa.admin.module.business.wms.stock.domain.entity.StockEntity;
import net.lab1024.sa.admin.module.business.wms.stock.domain.form.StockAddForm;
import net.lab1024.sa.admin.module.business.wms.stock.domain.form.StockQueryForm;
import net.lab1024.sa.admin.module.business.wms.stock.domain.form.StockUpdateForm;
import net.lab1024.sa.admin.module.business.wms.stock.domain.vo.StockVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 库存信息表（单租户版） Service
 *
 * @Author ADog
 * @Date 2025-09-20 15:55:03
 * @Copyright 1.0
 */

@Service
public class StockService {

    @Resource
    private StockDao stockDao;

    /**
     * 分页查询
     */
    public PageResult<StockVO> queryPage(StockQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<StockVO> list = stockDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(StockAddForm addForm) {
        StockEntity stockEntity = SmartBeanUtil.copy(addForm, StockEntity.class);
        stockDao.insert(stockEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(StockUpdateForm updateForm) {
        StockEntity stockEntity = SmartBeanUtil.copy(updateForm, StockEntity.class);
        stockDao.updateById(stockEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        stockDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long stockId) {
        if (null == stockId){
            return ResponseDTO.ok();
        }

        stockDao.deleteById(stockId);
        return ResponseDTO.ok();
    }
}
